<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateArticlesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('articles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title')->comment('文章标题');
            $table->string('sub_title')->comment('文章副标题');
            $table->longText('content')->comment('文章内容');
            $table->string('openness')->comment('公开级别 public 公开；private 私密；password 密码');
            $table->string('status')->comment('状态 draft 草稿；wait_audit 待审核；published 已发布');
            $table->timestamp('published_at')->nullable()->comment('发布时间 为空表示立即发布，不为空表示定时发布');
            $table->unsignedInteger('category_id')->comment('所属分类');
            $table->json('tag_ids')->nullable()->comment('文章标签');
            $table->boolean('has_image')->default(false)->comment('是否有图片');
            $table->boolean('is_top')->default(false)->comment('是否置顶');
            $table->integer('read_quantity')->default(0)->comment('阅读量');
            $table->timestamps();

            $table->softDeletes();
            $table->index('status');
            $table->index('category_id');

            $table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('articles');
    }
}
